package com.designpattern.softwaredesignpatternstudy.principle;

/**
 * @Author: Jiangxx
 * @Date: 2021/09/28
 * @Description: 依赖倒置原则:要面向接口编程，不要面向实现编程。"顾客购物程序"
 * 依赖倒置原则是实现开闭原则的重要途径之一，它降低了客户与实现模块之间的耦合。
 */
public class DependenceInversionPrinciple {
    public static void main(String[] args) {
        Customer customer = new Customer();
        ShaoguanShop shaoguanShop = new ShaoguanShop();
        WuyuanShop wuyuanShop = new WuyuanShop();
        customer.shopping(shaoguanShop);
        customer.shopping(wuyuanShop);
    }
}


//商店
interface Shop {
    String sell(); //卖
}
//韶关网店
class ShaoguanShop implements Shop {
    @Override
    public String sell() {
        return "韶关土特产：香菇、木耳……";
    }
}
//婺源网店
class WuyuanShop implements Shop {
    @Override
    public String sell() {
        return "婺源土特产：绿茶、酒糟鱼……";
    }
}
//顾客
class Customer {
    public void shopping(Shop shop) {
        //购物
        System.out.println(shop.sell());
    }
}